-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix composable templates with subobjects: false
#97317
Fix composable templates with subobjects: false
#97317
Conversation
Hi @eyalkoren, I've created a changelog YAML for you. |
Pinging @elastic/es-search (Team:Search) |
server/src/main/java/org/elasticsearch/index/mapper/MapperService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the chosen path of determining whether there is an explicit sub-objects setting before merging is the right one! Therefore the solution proposed LGTM. Thanks @eyalkoren for the PR.
…posable-templates
…mplates' into fix2-subobjects-composable-templates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the PR @eyalkoren 👍
Does this fix the case when we have conflicting I worry a bit that this is a special-case fix for one specific type of possible conflict, and that maybe we need to take a step back and see if there is a better way of doing this more generally. In particular, it might be worth trying to merge the templates as json maps rather than as parsed mappings? As I understand it, v2 templates are supposed to be parseable so that they can be verified when PUT, but I don't think that necessarily means that we need to merge them together as mappings at index creation time. I think it might also be worth getting some input from @elastic/es-data-management given that they own the template code. |
@romseygeek thanks for your input! I agree that there is a bigger issue here, I'll try to define it in more details. Firstly, just to clarify, this is not a fix for handling of conflicting directives, it is a fix for failure to merge valid (non-conflicting) mappings. I only added a validation for conflicting explicit Having said that, and maybe that's your point, it doesn't fix failure to merge non-root valid mappings, such as: "mappings" : {
"properties" : {
"parent" : {
"subobjects" : false,
"type" : "object",
}
}
} and "mappings" : {
"properties" : {
"parent" : {
"properties" : {
"child.grandchild" : {
"type" : "keyword"
}
}
}
}
} Merging the two above will also fail. "mappings" : {
"properties" : {
"parent" : {
"subobjects" : false,
"type" : "object",
"properties" : {
"child.grandchild" : {
"type" : "keyword"
}
}
}
}
} So, while I agree and even willing to take the challenge to find a wider fix, wouldn't you think it's better to eliminate the higher-impact issue?
I am not sure what this means, let's discuss this. |
Summarizing my offline discussion with @romseygeek: we may be able to generically solve this problem by merging mappings in their raw form first, before parsing them, as in Another alternative is to postpone the object expansion based on @dakrone your input on this would be very helpful. |
Update (for my future self mostly): I added a test with the exact example described above that fails as expected. |
I think it's likely that we'll still get exceptions, it's just that they'll be different exceptions? For example, overriding an object mapper with a float mapper will then throw an exception at parse time, because float mappers can't have a |
It will then depend in the order of the merge. The point is that it is not so much about how tests will fail, but that we'll have to reproduce the same behavior in raw mapping merge as we get with parsed mappings merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took an initial look and it looks pretty good. I left only a couple of comments, and tomorrow I plan to spend some time manually testing this. I definitely think someone on the mapping side should take a look, as I'm only an expert on the template side, not the mapping side.
.../src/yamlRestTest/resources/rest-api-spec/test/indices.put_index_template/15_composition.yml
Outdated
Show resolved
Hide resolved
.../src/yamlRestTest/resources/rest-api-spec/test/indices.put_index_template/15_composition.yml
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/mapper/MapperService.java
Outdated
Show resolved
Hide resolved
@dakrone when adding the custom merge javadoc, I realized that we never really went carefully over all mapping parameters to identify which we want to preserve when we merge, like we plan to do with Also - are there other mapping parameters that can be set at the root level (like |
@elasticsearchmachine run elasticsearch-ci/bwc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for all the work on this @eyalkoren
server/src/main/java/org/elasticsearch/index/mapper/MapperService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes LGTM, though I'm far from an expert in mapping stuff. The template changes seem harmless enough. Left just a couple small comments.
server/src/test/java/org/elasticsearch/common/xcontent/support/XContentHelperTests.java
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/mapper/MapperService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/mapper/MappingParser.java
Outdated
Show resolved
Hide resolved
note that this should cause CI failures until elastic#97317 is merged
Addressed with the new raw mapping merge
Dear all,
Here the final index_template:
If I try to do the PUT of 1 first document in version 8.10 I get an error, while in 8.9.2 it created correctly the new index by merging the mappings.
|
@chiarch84 thanks for reporting! |
I finally got to actually look and there is indeed a test case I added for it, but maybe yours is a specific scenario that is not properly covered. |
Fixes #96768
A fix proposal based on the identified root cause.
The problem in general is that mapping properties parsing is affected by the
subobjects
setting, so if multiple mappings are merged, whenever explicitsubobjects
setting is encountered, formerly parsed mappings become invalid.What I tried in this PR is to determine whether there is an explicit
subobjects
setting within a list of mappings before parsing (and merging) them. This allows for consistent parsing and merging of component templates when processing and validating composable component templates.If this fix proposal is evaluated as a valid path, we still need to add some unit tests, for example:
composedOf
listsubobjects
settings